package fragments;
import com.cachopoid.R;
import com.cachopoid.activity.MainActivity;

import android.app.Activity;
import android.app.Fragment;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;


public class FragmentEnviaIncidencia extends Fragment {
    /**
     * The fragment argument representing the section number for this
     * fragment.
     */
    private static final String ARG_SECTION_NUMBER = "section_number";

    EditText eTxtIncidencia = null;
    /**
     * Returns a new instance of this fragment for the given section
     * number.
     */
    public static FragmentEnviaIncidencia newInstance(int sectionNumber) {
    	FragmentEnviaIncidencia fragment = new FragmentEnviaIncidencia();
        Bundle args = new Bundle();
        args.putInt(ARG_SECTION_NUMBER, sectionNumber);
        fragment.setArguments(args);
        return fragment;
    }

    public FragmentEnviaIncidencia() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_envio_incidencia, container, false);
        eTxtIncidencia = (EditText) rootView.findViewById(R.id.eTxtIncidencia);
        Button btnEnviar = (Button) rootView.findViewById(R.id.btnEnviar);
        btnEnviar.setOnClickListener(new enviarMail());
        
        return rootView;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        ((MainActivity) activity).onSectionAttached(
                getArguments().getInt(ARG_SECTION_NUMBER));
    }
    
    
    private class enviarMail implements View.OnClickListener{
        
       
        
        public void onClick(View v){
        	try {
        		//String copias[" "];
    	    	Intent emailIntent = new Intent(Intent.ACTION_SEND);
    	        emailIntent.setData(Uri.parse("mailto:"));

				//String[] to = direccionesEmail;
    	        String to = "avilamenendez.rafa@gmail.com";
    	        String asunto = "dale";
    	        String mensaje = "prueba blablablablabla";
    	        
    	        emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
    	        emailIntent.putExtra(Intent.EXTRA_CC, "");
    	        emailIntent.putExtra(Intent.EXTRA_SUBJECT, asunto);
    	        emailIntent.putExtra(Intent.EXTRA_TEXT, mensaje);
    	        emailIntent.setType("message/rfc822");
    	        startActivity(emailIntent);
            
        	} catch (ActivityNotFoundException activityException) {
    			Log.e("enviar mail", "Envio mail erroneo", activityException);
    		}
        }
    }
    
}
